
"""
    pycoopiler - a compiler developed for PCS2056 course (Compilers) at Poli-USP
    Copyright (C) 2008 Andre Felipe Santos    
    Copyright (C) 2008 Rodrigo Rodrigues da Silva

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
"""

class automaton:
    "this class implements a simple engine for general purpose FDA's"
    
    def __init__(self, transitions, initial_state = 0, final_states = ['F']):
        self.__transitions = transitions
        self.__initial = initial_state
        self.final = final_states
        self.reset()
    
    def next_state(self, char):
        if self.__transitions.has_key((self.current_state, char)):
            self.current_state = self.__transitions[(self.current_state, char)]
        else:
            raise Exception ('Lexical error: transition not present in automaton')
        return self.current_state
    
    def reset(self):
        self.current_state = self.__initial
        
    def clear(self):
        self.current_state = None
        self.__transitions = {}
    
    
    

